package br.com.lh.urabuilder.view.arrow
{
	import br.com.lh.urabuilder.util.CoordinatesUtils;
	import br.com.lh.urabuilder.view.ActionComponent;
	
	import flash.geom.Point;
	
	import mx.controls.Label;
	import mx.styles.StyleManager;
	
	
	//FIXME: APPLY DECORATOR PATTERN.
	public class ArrowContainerWithText extends ArrowContainer
	{
		private var arrowLabel:Label = new Label();
		
		[Bindable]
		public var text:String;
		
		public function ArrowContainerWithText(startPoint:Point,endPoint:Point,text:String=""){
			super(startPoint,endPoint);
			this.text = text;
		}
		
		public function set arrowText(text:String):void{
			arrowLabel.text = text;
			arrowLabel.styleName = StyleManager.getStyleDeclaration('AccordionHeader');
			arrowLabel.x = width/2;
			arrowLabel.rotation = getCorrectOrientedAngle(CoordinatesUtils.getAngleInDegrees(startPoint,endPoint));
		}
		
		public function get arrowText():String{
			return arrowLabel.text;
		}
		
		protected function drawContainer():void{
			removeChild(arrowLabel);
			addChild(arrowLabel);
			
		}
		
		private function getCorrectOrientedAngle(baseAngle:Number):Number{
			if (baseAngle >90 && baseAngle < 270){
				return -180;
			}
			return 0;
		}
		
		
	}
}